package com.centaline.androidsalesblog.adapter;

import android.content.Context;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;

import com.bumptech.glide.DrawableRequestBuilder;
import com.centaline.androidsalesblog.R;
import com.centaline.androidsalesblog.adapter.viewholder.SchoolVH;
import com.centaline.androidsalesblog.model.businissobject.SchoolBo;
import com.centanet.framework.base.BaseAdapter1;
import com.centanet.framework.glide.GlideLoad;

import java.util.ArrayList;

/**
 * 学区
 * Created by guilin on 16/1/11.
 */
public class SchoolAdapter extends BaseAdapter1<SchoolVH> {

    private final DrawableRequestBuilder<String> requestBuilder;
    private final ArrayList<SchoolBo> list;

    public SchoolAdapter(Context context, DrawableRequestBuilder<String> requestBuilder, ArrayList<SchoolBo> list) {
        super(context);
        this.requestBuilder = requestBuilder;
        this.list = list;
    }

    @Override
    protected int inflateByLayoutId() {
        return R.layout.item_school;
    }

    @Override
    protected SchoolVH viewHolder(View view) {
        return new SchoolVH(view);
    }

    @Override
    public void onBindViewHolder(SchoolVH holder, int position) {
        final SchoolBo schoolBo = list.get(position);
        GlideLoad.load(new GlideLoad.Builder(requestBuilder, schoolBo.getDefaultImg())
                .placeHolder(R.drawable.ic_centa_square_logo)
                .error(R.drawable.ic_centa_square_logo)
                .openWifiSwitch()
                .into(holder.img_logo));
        holder.atv_name.setText(schoolBo.getSchoolShortName());
        holder.atv_tag_fir.setText(String.format("%s  %s", schoolBo.getRegion(), schoolBo.getGscope()));
        holder.atv_sale_count.setText(Html.fromHtml("<font color=\"#FF7C12\">" + schoolBo.getSchoolSPostNum() + "</font>套房源"));
        StringBuilder schoolGradeAndFeature = new StringBuilder();
        if (!TextUtils.isEmpty(schoolBo.getSchoolGrade())) {
            schoolGradeAndFeature.append(schoolBo.getSchoolGrade()).append("、");
        }
        schoolGradeAndFeature.append(schoolBo.getSchoolFeature());
        holder.customListTagView.setTags(schoolGradeAndFeature.toString(), "、");
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
}
